package org.footballmanager.pandafootball.system.controller;

import org.footballmanager.pandafootball.common.constants.Constants;
import org.footballmanager.pandafootball.system.domain.FootTt;
import org.footballmanager.pandafootball.system.form.impl.FootTtSearchForm;
import org.footballmanager.pandafootball.system.service.FootQdService;
import org.footballmanager.pandafootball.system.service.FootSjService;
import org.footballmanager.pandafootball.system.service.FootTtService;
import org.footballmanager.pandafootball.system.service.FootUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

@Controller
@SessionAttributes("footTtSearchForm")
@RequestMapping("/foot/footTt")
public class FootTtController extends AddAndEditController<FootTt>{
	/* 实体名称 */
	private static final String ENTITYNAME = "footTt";
	private static final String EDITPAGE = String.format(Constants.EDITPAGE, Constants.FOOT, ENTITYNAME);
	private static final String LISTPAGE = String.format(Constants.LISTPAGE, Constants.FOOT, ENTITYNAME);
	private static final String VIEWPAGE = String.format(Constants.VIEWPAGE, Constants.FOOT, ENTITYNAME);

	@Autowired
	private FootTtService footTtService;
	@Autowired
	private FootUserService footUserService;
	@Autowired
	private FootSjService footSjService;
	@Autowired
	private FootQdService footQdService;

    /**
     * 抽象方法
     *
     * @return 实体名称
     */
    @Override
    protected String getEntityName() {
        return ENTITYNAME;
    }

    /**
	 * 初始化
	 * @param map 参数
	 * @param footTtSearchForm 条件参数
	 */
	@ModelAttribute
	public void init(Model map, @ModelAttribute FootTtSearchForm footTtSearchForm){
		map.addAttribute("userList", footUserService.findGameIdIsNotNull());
		map.addAttribute("sjList", footSjService.getall());
		map.addAttribute("qdList", footQdService.getall());
		FootTtSearchForm newFootTtSearchForm = new FootTtSearchForm();
		if(footTtSearchForm != null){
			newFootTtSearchForm = footTtSearchForm;
		}
		map.addAttribute(String.format(Constants.FORMNAME, ENTITYNAME), newFootTtSearchForm);
	}

	@RequestMapping(value="/search")
	public String search(Model map, @ModelAttribute FootTtSearchForm footTtSearchForm) {
        footTtService.search(ENTITYNAME, map, footTtSearchForm);
		return LISTPAGE;
	}

	@RequestMapping(value = "/edit", method = RequestMethod.GET)
	public String openEditPage(Model map, @RequestParam Long id) {
		map.addAttribute(ENTITYNAME, footTtService.get(id));
		return EDITPAGE;
	}
	
	@RequestMapping(value = "/view", method = RequestMethod.GET)
	public String openViewPage(Model map, @RequestParam Long id, @ModelAttribute FootTtSearchForm footTtSearchForm) {
		map.addAttribute(String.format(Constants.FORMNAME, ENTITYNAME), footTtSearchForm);
		map.addAttribute(ENTITYNAME, footTtService.get(id));
		return VIEWPAGE;
	}	
		
}
